package com.xiaowan.user.service.impl;

import com.xiaowan.model.common.dtos.ResponseResult;
import com.xiaowan.model.common.enums.AppHttpCodeEnum;
import com.xiaowan.model.user.WorkInfo;
import com.xiaowan.user.mapper.WorkInfoDao;
import com.xiaowan.user.service.WorkInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * 实现功能：工作信息
 *
 * @author 作者[admin]
 * @version 1.0.00 2023-04-09 19:22
 */
@Service
public class WorkInfoServiceImpl implements WorkInfoService {
    @Autowired
    private WorkInfoDao workInfoDao;


    @Override
    public ResponseResult perfectMessage(WorkInfo workInfo) {
        if (workInfo == null) {
            return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);
        }
        //初始化参数
        workInfo.setCreateTime(new Date());
        try {
            workInfoDao.insert(workInfo);
            return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
        }catch (Exception e) {
            e.printStackTrace();
            return ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR);
        }
    }

    @Override
    public ResponseResult findByUserInfoCode(Integer id) {
        if (id == null) {
            return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_REQUIRE);
        }
        WorkInfo workInfo = workInfoDao.selectById(id);
        if (workInfo == null) {
            return ResponseResult.errorResult(AppHttpCodeEnum.DATA_NOT_EXIST);
        }
        return ResponseResult.okResult(workInfo);
    }

    @Override
    public ResponseResult updateWorkInfo(WorkInfo workInfo) {
        if (workInfo == null) {
            return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);
        }
        workInfo.setUpdateTime(new Date());
        try {
            workInfoDao.updateById(workInfo);
            return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
        }catch (Exception e) {
            e.printStackTrace();
            return ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR);
        }
    }


}
